const hasPermission = {
  install(Vue, options) {
    Vue.directive('has-permission', {
      bind(el, binding, vnode) {
        // 获取按钮权限列表buttonList，buttonList包含的按钮是没有权限访问的，界面需要删除对应按钮。
        const permissionList = vnode.context.$route.meta.buttonList;
        if (permissionList && permissionList.length) {
          const index = permissionList.findIndex((value) => {
            return value.buttonCode === binding.value;
          });
          Vue.nextTick(() => index > -1 && el.parentNode ? el.parentNode.removeChild(el) : el.remove());
        }
      }
    });
  }
};

export default hasPermission;
